package com.Day11;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * @author: 若若叶
 * @date: 2021/7/19 14:38
 * FileName: MyFileInputStream
 * Description: 输入字节流
 */
public class MyFileInputStream {
    public static void main(String[] args) {
        //新建流
        FileInputStream fileInputStream = null;
        try {
            //添加文件
            fileInputStream = new FileInputStream("E:\\JavaStudy\\DailyStudy\\src\\com\\Day11\\file");
            //新建4个字节的数组，用于4个4个取
            byte[] bytes = new byte[4];
            //用于获取本次获取几个字节  -1表示没有获取到
            int readcount = 0;
            while ((readcount = fileInputStream.read(bytes))!=-1){
                //把数组转成字符串输出，从0到读到的个数位置readcount
                System.out.print(new String(bytes,0,readcount));
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fileInputStream!=null){
                try {
                    //关闭流
                    fileInputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
